<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>京东</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <style media="screen">
    .content{
      width: 100%;
      padding: 0 15px;
    }
    .content ul {
        width: 100%;
        margin-top: 5px;
        overflow: hidden;
    }

    .content ul li {
        width: 49%;
        background-color: #fff;
        padding: 5px;
        float: left;
        margin-left: 2%;
        margin-top: 10px;
        box-sizing: border-box;
        overflow: hidden;
    }

    .content ul li:nth-child(2n+1) {
        margin-left: 0;
    }

    .content ul li>.goods_picture {
        width: 100%;
        height: 155px;
    }

    .content ul li>.goods_picture img {
        display: block;
        width: 100%;
        height: 100%;
    }

    .content ul li>.intro {
      width: 100%;
      overflow: hidden;
    }

    .content ul li>.intro span:first-child {
        width: 100%;
        overflow: hidden;
        font-size: 12px;
        line-height: 20px;
    }

    .content ul li>.intro span:first-child img {
        display:inline-block;
        margin-top:2px;
        width:30px;
        height:12px;
        margin-right:2px;
    }
    .content ul li>.price{
      width: 100%;
      overflow: hidden;
      display: flex;
      justify-content: space-between;
      margin-top: 8px;
    }
    .content ul li>.price .price_item{
      display: flex;
      width: auto;

    }
    .content ul li>.price .price_item:last-child{
      height: 15px;
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 15px;
    }
    .content ul li>.price .price_item span:nth-child(1){
      width: auto;
      height: 15px;
      font-size: 10px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 17px;
    }
    .content ul li>.price .price_item span:nth-child(2){
      width: auto;
      height: 15px;
      font-size: 10px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #FF4242;
      line-height: 17px;
    }
    .content ul li>.price .price_item span:nth-child(3){
      width: auto;
      height: 15px;
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #FF4242;
      line-height: 15px;
    }
    </style>
</head>

<body>
    <div id="app">
      <div class="content">
            <ul>
                <li v-for='item in dataList' @click='openGoodsDtailsPage(item.goodsId)'>
                    <div class="goods_picture"><img :src="item.mainPic" alt=""></div>
                    <div class="intro">
                      <span class="aui-ellipsis-2"><img src="../../image/pdd_details_icon.png" alt="">{{item.dtitle}}</span>
                      <!-- <span class="aui-ellipsis-2" v-else><img src="../../image/tb_search.png" alt="">{{item.dtitle}}</span> -->
                      <!-- <span class="icon"><img src="" alt=""></span> -->
                      </div>
                    <div class="price">
                      <div class="price_item"><span>券后</span><span>￥</span><span>{{item.actualPrice}}</span></div>
                      <div class="price_item">已售{{item.monthSales}}</div>
                    </div>
                </li>
            </ul>
      </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/cling.js"></script>
<script type="text/javascript">
    apiready = function() {
      vm.init();
      api.addEventListener({
          name: 'getPdd'
      }, function(ret, err){
          if( ret ){
              //  alert( JSON.stringify( ret ) );
               vm.init(ret.value.cid)
          }else{
               alert( JSON.stringify( err ) );
          }
      });

      vm.initRefresh();
      vm.bottomLoad();

    }
    var vm = new Vue({
        el: '#app',
        data: {
          dataList:[],
          catId:'',
          offset:0
        },
        methods: {
           clearData: function() {
                vm.dataList = [];
           },
           init:function(catId,isClick){
             vm.catId = catId;
             if (isClick) {
                 vm.offset += 10;
             } else { // 下拉刷新 或者 初次加载
                 vm.offset = 0;
             }
             cl.openLoading();
             api.ajax({
                 url: cl.apiServer + 'pdd/getGoodsRecommend',
                 method: 'post',
                 headers: {
                     'Content-Type': 'application/json;charset=utf-8',
                     token:cl.userToken
                 },
                 data: {
                     body: {
                         catId:catId,
                         channelType:4,
                         limit:10,
                         offset:vm.offset,
                         listId:'',
                         version:cl.deviceInfo().appVersion,
                         mobileInfo:cl.systemType()
                     }
                 }
             }, function(ret, err) {
                 console.log(JSON.stringify(ret));
                 if(ret){
                   if(ret.code==0){
                     cl.closeLoading();
                     if(ret.data.goodsList.length==0){
                        vm.dataList = [];
                     }else if (ret.data.goodsList.length<10) {
                        vm.dataList = vm.dataList.concat(ret.data.goodsList);
                     }else{
                        vm.dataList = vm.dataList.concat(ret.data.goodsList);
                     }
                   }
                 }
             })
           },
           //下拉刷新
           initRefresh: function() {
               cl.openRefresh(function() {
                   vm.init(vm.catId, false);
               })
           },
           //上拉加载
           bottomLoad: function() {
               cl.scrollBottom(function() {
                 vm.init(vm.catId, true);
               })
           },
           openGoodsDtailsPage: function(id) {
             console.log(id);
               cl.openWin({
                   name: 'pdd_goods_deatils',
                   pageParam: {
                       id: id
                   }
               })
           }
        }
    });
</script>

</html>
